<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
        <meta name="description" content="">
        <meta name="author" content="">

        <title>后台</title>

        <link href="__PUBLIC__/images/favicon.ico" rel="shortcut icon" />

        <!-- Bootstrap core CSS -->
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-theme.min.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/dashboard.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/icheck/all.css" />
        <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-datetimepicker.css" />
    </head>

    <body>

    <include file="Common/topNav" />

    <div class="container-fluid">
        <div class="row">
            <include file="Common/leftMenu" />
            <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
                <div class="cont-title clearfix">
                    <div class="title">租赁需求</div>
                </div>
                <form class="jc-search form-inline searchForm" action="{:U('Admin/Rental/index')}" method="post">
                    <div class="form-group">
                        <label>楼宇名称:</label>
                        <select class="form-control" name="house_id">
                            <option value="">全部</option>
                            <volist name="houseList" id="item">
                                <option <if condition="$houseId eq $item['id']">selected="selected"</if> value="{$item.id}">{$item.name}</option>
                            </volist>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>状态:</label>
                        <select class="form-control" name="audit">
                            <option value="">全部</option>
                            <option value="1" <if condition="$audit eq 1">selected</if>>待审核</option>
                            <option value="2" <if condition="$audit eq 2">selected</if>>已审核</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>申请时间:</label>
                        <div class='input-group date col-sm-7' id='datetimepicker'>
                            <input type='text' value="{$_REQUEST['create_time']}" name="create_time" class="form-control " data-date-format="yyyy-mm-dd" />
                            <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span></span>
                        </div>
                    </div>
                    <input class="btn" type="submit" value="查询" />
                </form>
                <div class="table-responsive">
                    <table class="table table-striped table-hover" id="tableData">
                        <thead>
                            <tr>
                            	<th>序号</th>
                                <th>楼宇名称</th>
                                <th>楼宇地址</th>
                                <th>房号</th>
                                <th>面积（㎡）</th>
                                <th>租赁人</th>
                                <th>租赁人电话</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        <empty name="leaseList['list']">
                        	<tr>
                        		<td colspan="10">没有相关记录</td>
                        	</tr>
                        </empty>
                        <foreach name="leaseList['list']" item="lease">
                            <tr>
                            	<td>{$lease.id}</td>
                                <td>{$lease.name}</td>
                                <td>{$lease.position}</td>
                                <td>{$lease.room}</td>
                                <td>{$lease.area}</td>
                                <td>{$lease.contacts}</td>
                                <td>{$lease.contact_phone}</td>
                                <td><if condition="$lease.audit eq 1">
                                    未审核
                                    <else/>
                                    审核
                                </if></td>
                                <td>
                                    <a thisId="{$lease.id}" href="javascript:void(0);" class="audit" <if condition="$lease.audit eq 2">disable</if>>审核</a>
                                </td>
                            </tr>
                        </foreach>    
                        </tbody>
                    </table>
                    <div class="page">
                    	{$leaseList.page}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <include file="Common/modalHtmls" />
    <script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/icheck.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript">
    	$(function(){
    		$("input[type='checkbox']").iCheck({
    	        checkboxClass: 'icheckbox_flat-blue',
    	        radioClass: 'iradio_flat-blue',
    	        increaseArea: '10%'
    	    });
    		$("#add_lease").bind("click",addLease);
    		$("#del_lease").bind("click",delLeaseBatch);
    		$("#tableData .lease_detail").click(function(){
    			showDetail(this);
    		});
    		chooseAll();
    	});
    	
    	function chooseAll(){
    		$('#checkAll').on('ifChecked', function(event){
    			$("input[name='lease_check[]']:checkbox").each(function(){
    				var $this = $(this);
        			if(!$this.prop("disabled")){
        				$this.iCheck("check");
        			}
        		});
    		});
    		$('#checkAll').on('ifUnchecked', function(event){
    			$("input[name='lease_check[]']:checkbox").iCheck("uncheck");
    		});
    	}
    	
    	function addLease(){
    		common.htmlAjax("{:U('Admin/Lease/add')}", {}, function (html) {
                $("#commonModal").html(html).modal('toggle');
            });
    	}
    	
    	function delLeaseBatch(){
    		var str = "";
    		$("input[name='lease_check[]']:checkbox").each(function(){
    			if(true == $(this).is(':checked')){
    				str += "," + $(this).val();
    			}
    		});
    		if(str == ""){
    			common.alert("提示","请至少选择一条记录");
    			return;
    		}
    		common.confirm("提示","确认删除选中的楼宇吗？",function(){
	    		str = str.substring(1);
	    		var param = {id:str};
	    		$.ajax({
	                url: "{:U('Admin/Lease/delete')}",
	                type: "post",
	                dataType: "json",
	                data: param,
	                success: function (data) {
	                    if(data.status){
	                    	common.alert("提示","楼宇已成功删除!",function(){
	                            common.reload();
	                        });
	                    }
	                }
	            });
    		});
    	}
    	function showDetail(obj){
    		var id = $(obj).attr("thisId");
    		common.htmlAjax("{:U('Admin/Lease/detail')}", {id:id}, function (html) {
                $("#commonModal").html(html).modal('toggle');
            });
    	}
        $('#datetimepicker').datetimepicker({
            format: 'yyyy-mm-dd',
            language: 'ch',
            pickDate: true,
            pickTime: false,
            autoclose:true,
            minView:2,
            //pickerPosition:"bottom-left"
        });
    </script>
</body>
</html>
